<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class pro_print_mitra extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();

		$this->secure_session();
	}

function mitra_aktif()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Mitra");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE MITRA');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KTP');
			$this->excel->getActiveSheet()->setCellValue('E8', 'SITU');
			$this->excel->getActiveSheet()->setCellValue('F8', 'SIUP');
			$this->excel->getActiveSheet()->setCellValue('G8', 'NPWP');
			$this->excel->getActiveSheet()->setCellValue('H8', 'NAMA MITRA');
			$this->excel->getActiveSheet()->setCellValue('I8', 'ALAMAT LENGKAP');
			$this->excel->getActiveSheet()->setCellValue('J8', 'NO TELEPON');
			$this->excel->getActiveSheet()->setCellValue('K8', 'NO HANDPHONE');
			$this->excel->getActiveSheet()->setCellValue('L8', 'STATUS MITRA');
			$this->excel->getActiveSheet()->setCellValue('M8', 'NO KONTRAK');
			$this->excel->getActiveSheet()->setCellValue('N8', 'AWAL KERJA');
			$this->excel->getActiveSheet()->setCellValue('O8', 'AKHIR KERJA');
			$this->excel->getActiveSheet()->setCellValue('P8', 'FEE MITRA');
			$this->excel->getActiveSheet()->setCellValue('Q8', 'NO REKENING');
			$this->excel->getActiveSheet()->setCellValue('R8', 'NAMA BANK');
			$this->excel->getActiveSheet()->setCellValue('S8', 'ATAS NAMA');
			
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_mitra']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['ktp']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['situ']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['siup']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['npwp']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['nama_mitra']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_telp']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_hand']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['status_mitra']);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['no_kontrak']);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['awal_kerja']);
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['akhir_kerja']);
				$this->excel->getActiveSheet()->setCellValue('P'.$x, $rows2['fee_mitra']);
				$this->excel->getActiveSheet()->setCellValue('Q'.$x, $rows2['no_rekening']);
				$this->excel->getActiveSheet()->setCellValue('R'.$x, $rows2['nama_bank']);
				$this->excel->getActiveSheet()->setCellValue('S'.$x, $rows2['atas_nama']);
				$no++;
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Mitra"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:S'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('R')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('S')->setWidth(30);


		$this->excel->getActiveSheet()->getStyle('D1:S'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('S1:S'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Mitra Aktif_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_perangkat()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	(UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	(UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Perangkat_".$date);

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('D8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('F8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('G8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('H8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('I8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('J8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('K8', 'KETERANGAN');
			$this->excel->getActiveSheet()->setCellValue('L8', 'JENIS KEBUTUHAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['keterangan']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['jenis_kebutuhan']);
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Penggunaan Perangkat"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:L'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Perangkat_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function kontrol_pemakaian_listrik()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_pemakaian_listrik
					WHERE	(UPPER(no) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_pemakaian_listrik
					WHERE	(UPPER(no) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Pemakaian Listrik");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'NO TOKO');
			$this->excel->getActiveSheet()->setCellValue('D8', 'LOKASI TOKO');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA TENANT');
			$this->excel->getActiveSheet()->setCellValue('F8', 'JENIS USAHA');
			$this->excel->getActiveSheet()->setCellValue('G8', 'KWH AWAL METER');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KWH AKHIR METER');
			$this->excel->getActiveSheet()->setCellValue('I8', 'KWH PEMAKAIAN');
			$this->excel->getActiveSheet()->setCellValue('J8', 'TANGGAL PENAGIHAN');
			
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['kwh_pemakaian']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['tanggal']);
				$no++;
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Pemakaian Listrik"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:J'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15);


		$this->excel->getActiveSheet()->getStyle('D1:J'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('J1:J'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Pemakaian Listrik'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}
}
?>